package com.ashokvarma.bottomnavigation;

import ohos.agp.render.Canvas;

public abstract class BadgeItem<T extends BadgeItem<T>> {
    boolean isSetOffset = false;
    float offsetX;
    float offsetY;

    boolean mHideOnSelect;

    BottomNavigationBar bottomNavigationBar;

    private boolean mIsHidden = false;

    public T toggle() {
        if (mIsHidden) {
            return show();
        } else {
            return hide();
        }
    }

    public T show() {
        mIsHidden = false;
        if (bottomNavigationBar != null) {
            bottomNavigationBar.invalidate();
        }
        return getSubInstance();
    }

    public T hide() {
        mIsHidden = true;
        if (bottomNavigationBar != null) {
            bottomNavigationBar.invalidate();
        }
        return getSubInstance();
    }

    public boolean isHidden() {
        return mIsHidden;
    }

    public T setOffset(float offsetX, float offsetY) {
        isSetOffset = true;
        this.offsetX = offsetX;
        this.offsetY = offsetY;
        return getSubInstance();
    }

    public T clearOffset() {
        isSetOffset = false;
        return getSubInstance();
    }

    public boolean isHideOnSelect() {
        return mHideOnSelect;
    }

    public T setHideOnSelect(boolean hideOnSelect) {
        this.mHideOnSelect = hideOnSelect;
        return getSubInstance();
    }

    abstract T getSubInstance();

    abstract void drawToCanvas(
            Canvas canvas,
            float centerX,
            float centerY,
            float defaultOffsetX,
            float defaultOffsetY,
            int size,
            int padding);
}
